import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('WebSocketServer')
export class WebSocketServer extends Component {
    static server: WebSocket;

    protected start(): void {

    }

    public connect() {
        WebSocketServer.server = new WebSocket("ws://localhost:8080");

        WebSocketServer.server.onopen = () => {
            console.log('WebSocket server connected');
        };
        WebSocketServer.server.onmessage = (event) => {
            console.log('Message from server ', event.data);
        };
        WebSocketServer.server.onclose = () => {
            console.log('WebSocket server disconnected');
        };
    }
}


